﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MSBIHelper.Helper;
namespace MSBIHelper.UI
{
    public partial class Frm_Setting : Form
    {
        public Frm_Setting()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Util.UpdateAppSetting(dgvSetting);
                MessageBox.Show("Done!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Frm_Setting_Load(object sender, EventArgs e)
        { 
            LoadAppSetting();
            //dgvSetting.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            //dgvSetting.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            //dgvSetting.AutoSize = true;
            dgvSetting.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
            dgvSetting.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCells);
        }

      
        void LoadAppSetting()
        {
            dgvSetting.DataSource = Util.GetAppSetting();

            foreach (DataGridViewColumn col in dgvSetting.Columns)
            {
                if (col.HeaderText == "Key")
                {
                    col.ReadOnly = true;
                }
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                col.SortMode = DataGridViewColumnSortMode.NotSortable;
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string count = ParallelHelper.GetWorkThreadCount().ToString();
            MessageBox.Show(count);
        }

    }
}
